rpt = "./timing_report.txt"
timing_report = open(rpt).readlines()
def parse_timing_report(timing_report):
    temp_paths = []
    paths = []
    for line in range(len(timing_report)):
        if "Slack (VIOLATED)" in timing_report[line]:
            slack = float(timing_report[line][timing_report[line].find(":")+1:timing_report[line].find("ns")])
            snk = timing_report[line+3].split(" ")[-1].strip()
            print(slack, snk)
            temp_paths.append((slack,snk))
    for line in range(len(timing_report)): 
        for path in temp_paths:
            if path[1] in timing_report[line] and "Destination:" not in timing_report[line]:
                paths.append((path[0],timing_report[line-2].split(" ")[-1].strip(),path[1],timing_report[line-1].split(" ")[-1].strip()))
    return paths
paths = parse_timing_report(timing_report)
paths.sort()
f = open("osm.tcl", "w+")
for i in range(len(paths)):
	print("disconnect_net -net {zcu104_i/OSM_Array/inst/OSM_Array/osm_grp[0].osm_array["+str(i)+"].osm_inst/D[0]}  -objects [get_pins {zcu104_i/OSM_Array/inst/OSM_Array/osm_grp[0].osm_array["+str(i)+"].osm_inst/Q1_reg/C}]")
	print("connect_net -net " + paths[i][-1] + " -objects [get_pins {zcu104_i/OSM_Array/inst/OSM_Array/osm_grp[0].osm_array["+str(i)+"].osm_inst/Q1_reg/C}] -hierarchical")
	f.write("disconnect_net -net {zcu104_i/OSM_Array/inst/OSM_Array/osm_grp[0].osm_array["+str(i)+"].osm_inst/D[0]}  -objects [get_pins {zcu104_i/OSM_Array/inst/OSM_Array/osm_grp[0].osm_array["+str(i)+"].osm_inst/Q1_reg/C}]\n")
	f.write("connect_net -net " + paths[i][-1] + " -objects [get_pins {zcu104_i/OSM_Array/inst/OSM_Array/osm_grp[0].osm_array["+str(i)+"].osm_inst/Q1_reg/C}] -hierarchical\n")
f.close()